package jp.co.sega.sonic_jump.monthly.sum;

import java.util.Calendar;

public class Dates {

    public Calendar d25;
    public Calendar o31;
    public Calendar j1;
    public Calendar jun23;
    public Calendar j25;
    public Calendar now;

    public Dates() {
        now = Calendar.getInstance();

        d25 = getFutureDate(Calendar.DECEMBER, 25);
        o31 = getFutureDate(Calendar.OCTOBER, 31);
        j1 = getFutureDate(Calendar.JANUARY, 1);
        j25 = getFutureDate(Calendar.JANUARY, 25);
        jun23 = getFutureDate(Calendar.JUNE, 23);
    }

    private Calendar getFutureDate(int month, int day) {
        Calendar date = Calendar.getInstance();
        date.set(Calendar.MONTH, month);
        date.set(Calendar.DAY_OF_MONTH, day);

        // Se a data já passou neste ano, avança para o próximo ano
        if (date.before(now)) {
            date.add(Calendar.YEAR, 1);
        }

        return date;
    }
    
    public boolean isWithinNextDays(Calendar now, Calendar target, int daysDuration) {
    // Zera a hora para comparar apenas a data
    Calendar today = (Calendar) now.clone();
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);

    Calendar start = (Calendar) target.clone();
    start.set(Calendar.HOUR_OF_DAY, 0);
    start.set(Calendar.MINUTE, 0);
    start.set(Calendar.SECOND, 0);
    start.set(Calendar.MILLISECOND, 0);

    Calendar end = (Calendar) start.clone();
    end.add(Calendar.DAY_OF_YEAR, daysDuration - 1);

    return !today.before(start) && !today.after(end);
}

    public Calendar getd25() {
        return d25;
    }

    public Calendar geto31() {
        return o31;
    }

    public Calendar getj1() {
        return j1;
    }
    
    public Calendar getj25() {
        return j25;
    }
    
    public Calendar getjun23() {
        return jun23;
    }

    public Calendar getnow() {
        return now;
    }
}